Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fill identical pixels with transparency in subsequent frames when saving GIF #7568

Merged
merged 1 commit into from
Dec 21, 2023

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Nov 24, 2023

When saving multiple GIF frames, Pillow trims identical edges of each new frame. This PR goes further, setting the pixels that are not new in the next frame as transparent if Pillow is optimizing. If there is no transparency, try and allocate one.

I started work on this after seeing #6832 (comment). If I remove optimize=False from that code, then without this change the file size is 21.5mb. With this change, the file size is 8.1mb.

For a less dramatic example, the output of #617 (comment) is reduced from 408kb to 345kb

Because the only difference in output should be filesize, there are no new tests to demonstrate correctness. I have added a test to cover an exception caught if trying to add transparency when there is no room in the frame.

@alanhamlett
Copy link

Could this be causing the ValueError in #7777?

@radarhere
Copy link
Member Author

radarhere commented Feb 4, 2024

Yes, this would be the cause - but rather than just undoing this change, it would be better to adjust it, to both reduce filesize and to fix your problem. The quickest way of understanding how to do that would be for you to post a self-contained example of your problem in that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants